package dotdashdot.bradz.trendsettr;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.Button;
import android.widget.TextView;

public class ActivityInfo extends Activity{

	private ClassFonts fonts;
	private ClassNetworkHelper helper;
	private ClassUserCredentials credentials;
	private ApplicationGlobalVars globals;
	private ClassUberLogger logger;
	
	Handler myHandler = new Handler() {

  		boolean in_use = false;
  		
  	    @Override
  	    public void handleMessage(Message msg) {
  	        switch (msg.what) {
  	        case 5:
	        	format_credentials();
	        	break;
  	        default:
  	            break;
  	        }
  	    }
  	};
  	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_info);
		logger = new ClassUberLogger("ActivityInfo");
		
		fonts = new ClassFonts(this.getAssets());
		helper = new ClassNetworkHelper(this,((ApplicationGlobalVars) this.getApplication()));
		globals = ((ApplicationGlobalVars) this.getApplication());
		
		credentials = new ClassUserCredentials(globals);
		if(!credentials.logged_in){
			helper.apply_for_credentials(credentials, myHandler);
		}else{
			format_credentials();
		}
		format_content();
		
		logger.info("OnCreate Finished");
  	}
  	
  	@Override
    public void onResume(){
    	super.onResume();
    	if(!credentials.logged_in && !helper.applying()){
			helper.apply_for_credentials(credentials, myHandler);
		}else if(!helper.applying()){
			format_credentials();
		}
    	logger.info("OnResume Finished");
    }
  	
  	private void format_content(){
  		final Button navigation_text = (Button) findViewById(R.id.top_navigation_button);
		navigation_text.setTypeface(fonts.get_font("cond_medium"));
  		
		TextView info_header_about = (TextView) findViewById(R.id.info_header_about);
		TextView info_text_about = (TextView) findViewById(R.id.info_text_about);
		info_header_about.setTypeface(fonts.get_font("cond_bold"));
		info_header_about.setText("About Us");
		info_text_about.setTypeface(fonts.get_font("regular"));
		info_text_about.setText("We are a small group of programmers and artists who had an idea and a dream to see it come to life. "
				+ "For questions, comments, or complaints please send us an email at: mauvemoonman@gmail.com. We would love to hear from you!");
		
		TextView info_header_credits = (TextView) findViewById(R.id.info_header_credits);
		TextView info_text_credits = (TextView) findViewById(R.id.info_text_credits);
		info_header_credits.setTypeface(fonts.get_font("cond_bold"));
		info_header_credits.setText("Credits");
		info_text_credits.setTypeface(fonts.get_font("regular"));
		info_text_credits.setText("Art-UX: Stephanie Zimmerman\nBackend Development: Dmitry Saprykin\nBusiness-Marketing: Brian Worley\nSoftware Lead: Brad Zimmerman\n");
		logger.info("Done formatting content");
  	}
  	
  	private void format_credentials(){
		TextView user_name_text_view = (TextView) this.findViewById(R.id.user_name_footer);
    	TextView user_rank_text_view = (TextView) this.findViewById(R.id.user_rank_footer);
    	user_name_text_view.setTypeface(fonts.get_font("medium_italic"));
    	user_rank_text_view.setTypeface(fonts.get_font("medium"));
    	user_name_text_view.setText(credentials.name);
    	user_rank_text_view.setText("Trendsettr Rank: "+credentials.rank);
    	globals.set_credentials_store(credentials);
    	logger.info("Done formatting credentials");
    }
  	
}
